import requests
import base64
import matplotlib.pyplot as plt # plt 用于显示图片
import matplotlib.image as mpimg # mpimg 用于读取图片
import random
def getscore(url):
    """颜值评分"""
    import requests
    import base64
    import matplotlib.pyplot as plt # plt 用于显示图片
    import matplotlib.image as mpimg # mpimg 用于读取图片
    
    f=open(url,'rb')#二进制读写，转换base64
    base64_data = base64.b64encode(f.read())
    request_url = "https://aip.baidubce.com/rest/2.0/face/v3/detect"
    access_token = '24.f32a0e4d45b0b6ab456366fbcd261bbc.2592000.1610717103.282335-22845309'
    Secret_Key = 'YvS4GnniDo6ZRVm4ZEyvCnq7mu0s8sBe'
    API_Key = 'm4C3dq1ElAZEYEnd9fxiWlIj' 
    
    # 参数 
    params = {
        "image":base64_data,
        "image_type":"BASE64",
        "face_field":"beauty"
    }
    #请求
    request_url = request_url + "?access_token=" + access_token
    headers = {'content-type': 'application/json'}
    response = requests.post(request_url, data=params, headers=headers)
    if response:
        print ("经过百度智能云的AI大数据评分，您的颜值分数为：",response.json()['result']['face_list'][0]['beauty'])
        lena = mpimg.imread(url) 
        plt.imshow(lena) 
        plt.axis('off')
        # plt.show()
    result = response.json()['result']['face_list'][0]['beauty']
    return result


def randomcolor():
    """随机颜色"""
    colorArr = ['1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']
    color = ""
    for i in range(6):
        color += colorArr[random.randint(0,14)]
        the_color = "#"+color
    print (the_color)
    return the_color